package com.kevin.service.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.kevin.common.util.tree.TreeNode;
import com.kevin.service.base.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * sysmenu 实体类
 * @author makejava
 * @date 2023-04-06
 */
@TableName(value = "sys_menu")
@EqualsAndHashCode(callSuper = true)
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class SysMenu extends BaseEntity implements TreeNode {

    /** 上级ID，一级菜单为0 */
    @ApiModelProperty(value = "上级ID，一级菜单为0")
    @TableField("pid")
    private Long pid;

    /** 菜单名称 */
    @ApiModelProperty(value = "菜单名称")
    @TableField("name")
    private String name;

    /** 菜单URL */
    @ApiModelProperty(value = "菜单URL")
    @TableField("url")
    private String url;

    /** 授权标识(多个用逗号分隔，如：sys:menu:list,sys:menu:save) */
    @ApiModelProperty(value = "授权标识(多个用逗号分隔，如：sys:menu:list,sys:menu:save)")
    @TableField("authority")
    private String authority;

    /** 类型   0：菜单   1：按钮   2：接口 */
    @ApiModelProperty(value = "类型   0：菜单   1：按钮   2：接口")
    @TableField("type")
    private Integer type;

    /** 打开方式   0：内部   1：外部 */
    @ApiModelProperty(value = "打开方式   0：内部   1：外部")
    @TableField("open_style")
    private Integer openStyle;

    /** 菜单图标 */
    @ApiModelProperty(value = "菜单图标")
    @TableField("icon")
    private String icon;

    /** 排序 */
    @ApiModelProperty(value = "排序")
    @TableField("sort")
    private Integer sort;

    @Override
    public Serializable getParentId() {
        return pid;
    }

    @TableField(exist = false)
    private List<TreeNode> children;

    @TableField(exist = false)
    private String parentName;


    @Override
    public List<TreeNode> getChildren() {
        if(children == null){
            this.children = new ArrayList<>();
        }
        return children;
    }
}

